package com.ado.abyss.core.web.controller;

import java.util.List;

import com.ado.abyss.core.constants.LogEnum;
import com.ado.abyss.core.params.http.HttpResult;
import com.ado.abyss.core.params.page.PageRequest;
import com.ado.abyss.core.web.controller.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ado.abyss.core.dal.model.SysDict;
import com.ado.abyss.core.service.SysDictService;


@RestController
@RequestMapping(value = "/api/dict")
public class DictController extends BaseController {
	
	@Autowired
	@Qualifier(value = "sysDictService")
	private SysDictService sysDictService ;
	
	@PreAuthorize("hasAuthority('sys:dict:add') AND hasAuthority('sys:dict:edit')")
	@PostMapping(value="/save")
	public HttpResult save(@RequestBody SysDict record) {
		setLog(LogEnum.DICT_MODULE.getModuleName() , "新增机构接口：入参:" + record.toString());
		return HttpResult.ok(sysDictService.save(record));
	}

	@PreAuthorize("hasAuthority('sys:dict:delete')")
	@PostMapping(value="/delete")
	public HttpResult delete(@RequestBody List<SysDict> records) {
		setLog(LogEnum.DICT_MODULE.getModuleName(),"删除机构接口，入参为:" + records.toString());
		return HttpResult.ok(sysDictService.delete(records));
	}

	@PreAuthorize("hasAuthority('sys:dict:view')")
	@PostMapping(value="/findPage")
	public HttpResult findPage(@RequestBody PageRequest pageRequest) {
		setLog(LogEnum.DICT_MODULE.getModuleName() , "机构分页查询接口，入参：" + pageRequest.toString());
		return HttpResult.ok(sysDictService.findPage(pageRequest));
	}
	
	@PreAuthorize("hasAuthority('sys:dict:view')")
	@GetMapping(value="/findByLabel")
	public HttpResult findByLabel(@RequestParam String label) {
		setLog(LogEnum.DICT_MODULE.getModuleName() , "按Label查询机构接口，入参：label=" + label);
		return HttpResult.ok(sysDictService.findByLabel(label));
	}
}
